package com.fjb.config.listener;

import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description:监听本节点
 * @author hemiao
 * @time:2020年3月7日 下午4:33:55
 */
public class MyNodeCacheListener extends AbstractNodeCacheListener{
	
	private static final Logger log = LoggerFactory.getLogger(MyNodeCacheListener.class);
	 
    public MyNodeCacheListener() {
         super();
    }
 
    public MyNodeCacheListener(NodeCache nodeCache) {
        super(nodeCache);
    }
 
    @Override
    public void nodeChanged() throws Exception {
    	log.info("-----> com.fjb.config.listener.MyNodeCacheListener");
        ChildData childData = this.getNodeCache().getCurrentData();
        /**
         * 创建和更新 childData 不为 null
         * 删除  childData 为 null
         */
        if(childData != null){
            log.info("Path: " + childData.getPath());
            log.info("Stat:" + childData.getStat());
            log.info("Data: "+ new String(childData.getData(),"utf-8"));
        }
    }
	
}
